import Vue from 'vue'
import VueRouter from 'vue-router'

// 1、安装路由
Vue.use(VueRouter)

// 2、定义路由映射
// tabBar\tabBar\src\views\Home.vue
const home = () => import('../views/Home')
const category = () => import('../views/Category')
const shopcar = () => import('../views/Shopcar')
const profile = () => import('../views/Profile')

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    component: home
  },
  {
    path: '/category',
    component: category
  },
  {
    path: '/shopcar',
    component: shopcar
  },
  {
    path: '/profile',
    component: profile
  },
]

// 3、创建对象
const router = new VueRouter({
  mode: 'history',
  routes
})

// 4、导出对象
export default router

// 5、去掉重复路由报错
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};
